Micron Document
<!DOCTYPE html>
<html class="client-nojs vector-feature-night-mode-disabled vector-feature-language-in-header-enabled vector-feature-language-in-main-page-header-disabled vector-feature-page-tools-pinned-disabled vector-feature-toc-pinned-clientpref-1 vector-feature-main-menu-pinned-disabled vector-feature-limited-width-clientpref-1 vector-feature-limited-width-content-enabled vector-feature-custom-font-size-clientpref-1 vector-feature-appearance-pinned-clientpref-1 vector-sticky-header-enabled" lang="en" dir="ltr"><head>
<meta charset="UTF-8">
<title>Expression problem</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="canonical" href="https://en.wikipedia.org/wiki/Expression_problem"> <link href="./mw/ext.cite.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/ext.pygments.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.icons.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.search.codex.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/skins.vector.styles.css" rel="stylesheet" type="text/css">
<link href="./mw/user.styles.css" rel="stylesheet" type="text/css">
<meta name="ResourceLoaderDynamicStyles" content="">
<link rel="stylesheet" type="text/css" href="./mw/site.styles.css">
<link rel="stylesheet" type="text/css" href="./mw/noscript.css">
<link rel="stylesheet" type="text/css" href="./footer.css">
<link rel="stylesheet" type="text/css" href="./vector-2022.css">
</head>
<body class="skin--responsive skin-vector skin-vector-search-vue mediawiki ltr sitedir-ltr mw-hide-empty-elt ns-0 ns-subject page-Expression_problem rootpage-Expression_problem skin-vector-2022 action-view">
<div class="mw-page-container">
<div class="mw-page-container-inner">
<div class="mw-content-container">
<main id="content" class="mw-body">
<header class="mw-body-header vector-page-titlebar">
<h1 id="firstHeading" class="firstHeading mw-first-heading">
<span id="openzim-page-title" class="mw-page-title-main"><span class="mw-page-title-main">Expression problem</span></span>
</h1>
</header>
<a id="top"></a>
<div id="bodyContent" class="vector-body ve-init-mw-desktopArticleTarget-targetContainer" aria-labelledby="firstHeading" data-mw-ve-target-container="">
<div id="mw-content-text" class="mw-body-content mw-content-ltr" lang="en" dir="ltr"><div class="mw-content-ltr mw-parser-output" lang="en" dir="ltr">
<p>The <b>expression problem</b> is a challenging problem in <a href="Programming_language" title="Programming language">programming languages</a> that concerns the extensibility and modularity of statically typed data abstractions. The goal is to define a data abstraction that is extensible both in its representations and its behaviors, where one can add new representations and new behaviors to the data abstraction, without recompiling existing code, and while retaining static type safety (e.g., no casts). The statement of the problem exposes deficiencies in <a href="Programming_paradigm" title="Programming paradigm">programming paradigms</a> and <a href="Programming_language" title="Programming language">programming languages</a>. Philip Wadler, one of the co-authors of Haskell, has originated the term.
</p>
<meta property="mw:PageProp/toc">
<div class="mw-heading mw-heading2"><h2 id="History">History</h2></div>
<p><a href="Philip_Wadler" title="Philip Wadler">Philip Wadler</a> formulated the challenge and named it "The Expression Problem"<sup id="cite_ref-WadlerPost_1-0" class="reference"><a href="#cite_note-WadlerPost-1"><span class="cite-bracket">[</span>1<span class="cite-bracket">]</span></a></sup> in response to a discussion with Rice University's <a href="Racket_(programming_language)#Development" title="Racket (programming language)"><i>Programming Languages Team</i> (PLT)</a>.
He also cited three sources that defined the context for his challenge:
</p><p>The problem was first observed by <a href="John_C._Reynolds" title="John C. Reynolds">John Reynolds</a> in 1975.<sup id="cite_ref-Reynolds_2-0" class="reference"><a href="#cite_note-Reynolds-2"><span class="cite-bracket">[</span>2<span class="cite-bracket">]</span></a></sup> Reynolds discussed two forms of Data Abstraction: User-defined Types, which are now known as <a href="Abstract_data_types" class="mw-redirect" title="Abstract data types">Abstract Data Types</a> (ADTs) (not to be confused with <a href="Algebraic_data_types" class="mw-redirect" title="Algebraic data types">Algebraic Data Types</a>), and Procedural Data Structures, which are now understood as a primitive form of Objects with only one method. He argued that they are complementary, in that User-defined Types could be extended with new behaviors, and Procedural Data Structures could be extended with new representations. He also discussed related work going back to 1967.
Fifteen years later in 1990, <a href="William_Cook_(computer_scientist)" title="William Cook (computer scientist)">William Cook</a><sup id="cite_ref-CookOOPvsADT_3-0" class="reference"><a href="#cite_note-CookOOPvsADT-3"><span class="cite-bracket">[</span>3<span class="cite-bracket">]</span></a></sup>
applied Reynold's idea in the context of Objects and Abstract Data Types, which had both grown extensively. Cook identified the matrix of representations and behaviors that are implicit in a Data Abstraction, and discussed how ADTs are based on the behavioral axis, while Objects are based on the representation axis. He provides extensive discussion of work on ADTs and Objects that are relevant to the problem. He also reviewed implementations in both styles, discussed extensibility in both directions, and also identified the importance of static typing.
Most importantly, he discussed situations in which there was more flexibility than
Reynolds considered, including internalization and optimization of methods.
</p><p>At ECOOP '98, <a href="Shriram_Krishnamurthi" title="Shriram Krishnamurthi">Shriram Krishnamurthi</a> et al.<sup id="cite_ref-Synth_4-0" class="reference"><a href="#cite_note-Synth-4"><span class="cite-bracket">[</span>4<span class="cite-bracket">]</span></a></sup> presented a design pattern solution to the problem of simultaneously extending an expression-oriented programming language and its tool-set. They dubbed it the "expressivity problem" because they thought programming language designers could use the problem to demonstrate the expressive power of their creations. For PLT, the problem had shown up in the construction of DrScheme, now <a href="Racket_(programming_language)#DrRacket_IDE" title="Racket (programming language)">DrRacket</a>, and they solved it<sup id="cite_ref-FF_5-0" class="reference"><a href="#cite_note-FF-5"><span class="cite-bracket">[</span>5<span class="cite-bracket">]</span></a></sup> via a rediscovery of <a href="Mixin" title="Mixin">mixins</a>.<sup id="cite_ref-Mixins_6-0" class="reference"><a href="#cite_note-Mixins-6"><span class="cite-bracket">[</span>6<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-FKF_7-0" class="reference"><a href="#cite_note-FKF-7"><span class="cite-bracket">[</span>7<span class="cite-bracket">]</span></a></sup> To avoid using a programming language problem in a paper about programming languages, Krishnamurthi et al. used an old geometry programming problem to explain their pattern-oriented solution. In conversations with Felleisen and Krishnamurthi after the ECOOP presentation, Wadler understood the PL-centric nature of the problem and he pointed out that Krishnamurthi's solution used a cast to circumvent Java's type system. The discussion continued on the types mailing list, where Corky Cartwright (Rice) and <a href="Kim_Bruce" title="Kim Bruce">Kim Bruce</a> (Williams) showed how type systems for OO languages might eliminate this cast. In response Wadler formulated his essay and stated the challenge, "whether a language can solve the expression problem is a salient indicator of its capacity for expression." The label "expression problem" puns on expression = "how much can your language express" and expression = "the terms you are trying to represent are language expressions".
</p><p>Others co-discovered variants of the expression problem around the same time as Rice University's PLT, in particular Thomas Kühne<sup id="cite_ref-K_8-0" class="reference"><a href="#cite_note-K-8"><span class="cite-bracket">[</span>8<span class="cite-bracket">]</span></a></sup> in his dissertation, and Smaragdakis and Batory<sup id="cite_ref-SB_9-0" class="reference"><a href="#cite_note-SB-9"><span class="cite-bracket">[</span>9<span class="cite-bracket">]</span></a></sup> in a parallel ECOOP 98 article.
</p><p>Some follow-up work used the expression problem to showcase the power of programming language designs.<sup id="cite_ref-Scala0_10-0" class="reference"><a href="#cite_note-Scala0-10"><span class="cite-bracket">[</span>10<span class="cite-bracket">]</span></a></sup><sup id="cite_ref-Scala_11-0" class="reference"><a href="#cite_note-Scala-11"><span class="cite-bracket">[</span>11<span class="cite-bracket">]</span></a></sup>
</p><p>The expression problem is also a fundamental problem in multi-dimensional Software Product Line design and in particular as an application or special case of <a href="FOSD_program_cubes#Applications" title="FOSD program cubes">FOSD Program Cubes</a>.
</p>
<div class="mw-heading mw-heading2"><h2 id="Solutions">Solutions</h2></div>
<p>There are various solutions to the expression problem. Each solution varies in the amount of code a user must write to implement them, and the language features they require.
</p>
<ul><li><a href="Multiple_dispatch" title="Multiple dispatch">Multiple dispatch</a><sup id="cite_ref-Chambers_&amp;_Leavens,_Multi-Methods_12-0" class="reference"><a href="#cite_note-Chambers_&amp;_Leavens,_Multi-Methods-12"><span class="cite-bracket">[</span>12<span class="cite-bracket">]</span></a></sup></li>
<li><a href="Ruby_syntax#Open_classes" title="Ruby syntax">Ruby syntax §&nbsp;Open classes</a><sup id="cite_ref-Clifton_et._al.,_MultiJava_Open_Classes_13-0" class="reference"><a href="#cite_note-Clifton_et._al.,_MultiJava_Open_Classes-13"><span class="cite-bracket">[</span>13<span class="cite-bracket">]</span></a></sup></li>
<li><a href="Coproduct" title="Coproduct">Coproducts</a> of <a href="Functor" title="Functor">functors</a><sup id="cite_ref-14" class="reference"><a href="#cite_note-14"><span class="cite-bracket">[</span>14<span class="cite-bracket">]</span></a></sup></li>
<li><a href="Type_class" title="Type class">Type classes</a><sup id="cite_ref-Wehr_&amp;_Thiemann,_JavaGI_Type_Classes_15-0" class="reference"><a href="#cite_note-Wehr_&amp;_Thiemann,_JavaGI_Type_Classes-15"><span class="cite-bracket">[</span>15<span class="cite-bracket">]</span></a></sup></li>
<li>Tagless-final<sup id="cite_ref-Carette_et_al.,_Finally_tagless,_partially_evaluated:_Tagless_staged_interpreters_for_simpler_typed_languages_16-0" class="reference"><a href="#cite_note-Carette_et_al.,_Finally_tagless,_partially_evaluated:_Tagless_staged_interpreters_for_simpler_typed_languages-16"><span class="cite-bracket">[</span>16<span class="cite-bracket">]</span></a></sup> / Object algebras<sup id="cite_ref-Oliveira_&amp;_Cook,_Object_Algebras_17-0" class="reference"><a href="#cite_note-Oliveira_&amp;_Cook,_Object_Algebras-17"><span class="cite-bracket">[</span>17<span class="cite-bracket">]</span></a></sup></li>
<li>Polymorphic Variants<sup id="cite_ref-Code_Reuse_Through_Polymorphic_Variants_18-0" class="reference"><a href="#cite_note-Code_Reuse_Through_Polymorphic_Variants-18"><span class="cite-bracket">[</span>18<span class="cite-bracket">]</span></a></sup></li></ul>
<div class="mw-heading mw-heading2"><h2 id="Example">Example</h2></div>
<div class="mw-heading mw-heading3"><h3 id="Problem_description">Problem description</h3></div>
<p>We can imagine we do not have the source code for the following library, written in <a href="C_Sharp_(programming_language)" title="C Sharp (programming language)">C#</a>, which we wish to extend:
</p>
<div class="mw-highlight mw-highlight-lang-c# mw-content-ltr mw-highlight-lines" dir="ltr"><pre><span class="k">interface</span><span class="w"> </span><span class="n">IEvalExp</span>
<span class="p">{</span>
<span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">Eval</span><span class="p">();</span>
<span class="p">}</span>

<span class="k">class</span><span class="w"> </span><span class="nc">Lit</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">IEvalExp</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="nf">Lit</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">n</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">Eval</span><span class="p">()</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">N</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>

<span class="k">class</span><span class="w"> </span><span class="nc">Add</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">IEvalExp</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="nf">Add</span><span class="p">(</span><span class="n">IEvalExp</span><span class="w"> </span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">IEvalExp</span><span class="w"> </span><span class="n">right</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">left</span><span class="p">;</span>
<span class="w"> </span><span class="n">Right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">right</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="n">IEvalExp</span><span class="w"> </span><span class="n">Left</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="n">IEvalExp</span><span class="w"> </span><span class="n">Right</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">Eval</span><span class="p">()</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">Left</span><span class="p">.</span><span class="n">Eval</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">Right</span><span class="p">.</span><span class="n">Eval</span><span class="p">();</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>

<span class="k">static</span><span class="w"> </span><span class="k">class</span><span class="w"> </span><span class="nc">ExampleOne</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="n">IEvalExp</span><span class="w"> </span><span class="nf">AddOneAndTwo</span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Add</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">Lit</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">Lit</span><span class="p">(</span><span class="mi">2</span><span class="p">));</span>
<span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">EvaluateTheSumOfOneAndTwo</span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">AddOneAndTwo</span><span class="p">().</span><span class="n">Eval</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
<p>Using this library we can express the arithmetic expression <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">1 + 2</code> as we did in <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">ExampleOne.AddOneAndTwo()</code> and can evaluate the expression by calling <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">.Eval()</code>. Now imagine that we wish to extend this library, adding a new type is easy because we are working with an <a href="Object-oriented_programming" title="Object-oriented programming">Object-oriented programming language</a>. For example, we might create the following class:
</p>
<div class="mw-highlight mw-highlight-lang-c# mw-content-ltr mw-highlight-lines" dir="ltr"><pre><span class="k">class</span><span class="w"> </span><span class="nc">Mult</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">IEvalExp</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="nf">Mult</span><span class="p">(</span><span class="n">IEvalExp</span><span class="w"> </span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">IEvalExp</span><span class="w"> </span><span class="n">right</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">left</span><span class="p">;</span>
<span class="w"> </span><span class="n">Right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">right</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="n">IEvalExp</span><span class="w"> </span><span class="n">Left</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="n">IEvalExp</span><span class="w"> </span><span class="n">Right</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">Eval</span><span class="p">()</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">Left</span><span class="p">.</span><span class="n">Eval</span><span class="p">()</span><span class="w"> </span><span class="o">*</span><span class="w"> </span><span class="n">Right</span><span class="p">.</span><span class="n">Eval</span><span class="p">();</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>
</pre></div>
<p>However, if we wish to add a new function over the type (a new method in C# terminology), for example to pretty print an expression, we have to change the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">IEvalExp</code> interface and then modify all the classes that implement the interface. Another possibility is to create a new interface that extends the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">IEvalExp</code> interface and then create sub-types for <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">Lit</code>, <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">Add</code> and <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">Mult</code> classes, but the expression returned in <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">ExampleOne.AddOneAndTwo()</code> has already been compiled so we will not be able to use the new function over the old type. The problem is reversed in functional programming languages like <a href="F_Sharp_(programming_language)" title="F Sharp (programming language)">F#</a> where it is easy to add a function over a given type, but extending or adding types is difficult.
</p>
<div class="mw-heading mw-heading3"><h3 id="Problem_solution_using_object_algebra">Problem solution using object algebra</h3></div>
<p>Let us redesign the original library with extensibility in mind using the ideas from the paper <i>Extensibility for the Masses.</i><sup id="cite_ref-Oliveira_&amp;_Cook,_Object_Algebras_17-1" class="reference"><a href="#cite_note-Oliveira_&amp;_Cook,_Object_Algebras-17"><span class="cite-bracket">[</span>17<span class="cite-bracket">]</span></a></sup>
</p>
<div class="mw-highlight mw-highlight-lang-c# mw-content-ltr mw-highlight-lines" dir="ltr"><pre><span class="k">interface</span><span class="w"> </span><span class="n">ExpAlgebra</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span>
<span class="p">{</span>
<span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="nf">Lit</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="p">);</span>
<span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="nf">Add</span><span class="p">(</span><span class="n">T</span><span class="w"> </span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="n">right</span><span class="p">);</span>
<span class="p">}</span>

<span class="k">class</span><span class="w"> </span><span class="nc">ExpFactory</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">ExpAlgebra</span><span class="o">&lt;</span><span class="n">IEvalExp</span><span class="o">&gt;</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="n">IEvalExp</span><span class="w"> </span><span class="nf">Lit</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="nf">Lit</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="n">IEvalExp</span><span class="w"> </span><span class="nf">Add</span><span class="p">(</span><span class="n">IEvalExp</span><span class="w"> </span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">IEvalExp</span><span class="w"> </span><span class="n">right</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="nf">Add</span><span class="p">(</span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">right</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>

<span class="k">static</span><span class="w"> </span><span class="k">class</span><span class="w"> </span><span class="nc">ExampleTwo</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="n">T</span><span class="w"> </span><span class="nf">AddOneToTwo</span><span class="p">(</span><span class="n">ExpAlgebra</span><span class="o">&lt;</span><span class="n">T</span><span class="o">&gt;</span><span class="w"> </span><span class="n">ae</span><span class="p">)</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">ae</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="n">ae</span><span class="p">.</span><span class="n">Lit</span><span class="p">(</span><span class="mi">1</span><span class="p">),</span><span class="w"> </span><span class="n">ae</span><span class="p">.</span><span class="n">Lit</span><span class="p">(</span><span class="mi">2</span><span class="p">));</span>
<span class="p">}</span>
</pre></div>
<p>We use the same implementation as in the first code example but now add a new interface containing the functions over the type as well as a factory for the algebra. Notice that we now generate the expression in <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">ExampleTwo.AddOneToTwo()</code> using the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">ExpAlgebra&lt;T&gt;</code> interface instead of directly from the types. We can now add a function by extending the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">ExpAlgebra&lt;T&gt;</code> interface, we will add functionality to print the expression:
</p>
<div class="mw-highlight mw-highlight-lang-c# mw-content-ltr mw-highlight-lines" dir="ltr"><pre><span class="k">interface</span><span class="w"> </span><span class="n">IPrintExp</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">IEvalExp</span>
<span class="p">{</span>
<span class="w"> </span><span class="kt">string</span><span class="w"> </span><span class="nf">Print</span><span class="p">();</span>
<span class="p">}</span>

<span class="k">class</span><span class="w"> </span><span class="nc">PrintableLit</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">Lit</span><span class="p">,</span><span class="w"> </span><span class="n">IPrintExp</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="nf">PrintableLit</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="p">)</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="k">base</span><span class="p">(</span><span class="n">n</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">n</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">N</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="kt">string</span><span class="w"> </span><span class="nf">Print</span><span class="p">()</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">N</span><span class="p">.</span><span class="n">ToString</span><span class="p">();</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>

<span class="k">class</span><span class="w"> </span><span class="nc">PrintableAdd</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">Add</span><span class="p">,</span><span class="w"> </span><span class="n">IPrintExp</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="nf">PrintableAdd</span><span class="p">(</span><span class="n">IPrintExp</span><span class="w"> </span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">IPrintExp</span><span class="w"> </span><span class="n">right</span><span class="p">)</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="k">base</span><span class="p">(</span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">right</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="n">Left</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">left</span><span class="p">;</span>
<span class="w"> </span><span class="n">Right</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">right</span><span class="p">;</span>
<span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">IPrintExp</span><span class="w"> </span><span class="n">Left</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">IPrintExp</span><span class="w"> </span><span class="n">Right</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">get</span><span class="p">;</span><span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="kt">string</span><span class="w"> </span><span class="nf">Print</span><span class="p">()</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">Left</span><span class="p">.</span><span class="n">Print</span><span class="p">()</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="s">" + "</span><span class="w"> </span><span class="o">+</span><span class="w"> </span><span class="n">Right</span><span class="p">.</span><span class="n">Print</span><span class="p">();</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>

<span class="k">class</span><span class="w"> </span><span class="nc">PrintFactory</span><span class="w"> </span><span class="p">:</span><span class="w"> </span><span class="n">ExpFactory</span><span class="p">,</span><span class="w"> </span><span class="n">ExpAlgebra</span><span class="o">&lt;</span><span class="n">IPrintExp</span><span class="o">&gt;</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="n">IPrintExp</span><span class="w"> </span><span class="nf">Add</span><span class="p">(</span><span class="n">IPrintExp</span><span class="w"> </span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">IPrintExp</span><span class="w"> </span><span class="n">right</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="nf">PrintableAdd</span><span class="p">(</span><span class="n">left</span><span class="p">,</span><span class="w"> </span><span class="n">right</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span>

<span class="w"> </span><span class="k">public</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="n">IPrintExp</span><span class="w"> </span><span class="nf">Lit</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">n</span><span class="p">)</span>
<span class="w"> </span><span class="p">{</span>
<span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="k">new</span><span class="w"> </span><span class="nf">PrintableLit</span><span class="p">(</span><span class="n">n</span><span class="p">);</span>
<span class="w"> </span><span class="p">}</span>
<span class="p">}</span>

<span class="k">static</span><span class="w"> </span><span class="k">class</span><span class="w"> </span><span class="nc">ExampleThree</span>
<span class="p">{</span>
<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="nf">Evaluate</span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">ExampleTwo</span><span class="o">&lt;</span><span class="n">IPrintExp</span><span class="o">&gt;</span><span class="p">.</span><span class="n">AddOneToTwo</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">PrintFactory</span><span class="p">()).</span><span class="n">Eval</span><span class="p">();</span>
<span class="w"> </span><span class="k">internal</span><span class="w"> </span><span class="k">static</span><span class="w"> </span><span class="kt">string</span><span class="w"> </span><span class="nf">Print</span><span class="p">()</span><span class="w"> </span><span class="o">=&gt;</span><span class="w"> </span><span class="n">ExampleTwo</span><span class="o">&lt;</span><span class="n">IPrintExp</span><span class="o">&gt;</span><span class="p">.</span><span class="n">AddOneToTwo</span><span class="p">(</span><span class="k">new</span><span class="w"> </span><span class="n">PrintFactory</span><span class="p">()).</span><span class="n">Print</span><span class="p">();</span>
<span class="p">}</span>
</pre></div>
<p>Notice that in <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">ExampleThree.Print()</code> we are printing an expression that was already compiled in <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">ExampleTwo</code>, we did not need to modify any existing code. Notice also that this is still strongly typed, we do not need reflection or casting. If we would replace the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">PrintFactory()</code> with the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">ExpFactory()</code> in the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">ExampleThree.Print()</code> we would get a compilation error since the <code class="mw-highlight mw-highlight-lang-text mw-content-ltr" style="" dir="ltr">.Print()</code> method does not exist in that context.
</p>
<div class="mw-heading mw-heading2"><h2 id="See_also">See also</h2></div>
<ul><li><a href="FOSD_program_cubes#Applications" title="FOSD program cubes">Applications of FOSD program cubes</a></li>
<li><a href="Generic_programming" title="Generic programming">Generic programming</a></li>
<li><a href="POPLmark_challenge" title="POPLmark challenge">POPLmark challenge</a></li></ul>
<div class="mw-heading mw-heading2"><h2 id="References">References</h2></div>
<style data-mw-deduplicate="TemplateStyles:r1239543626">
/* start https://en.wikipedia.org/ */


.mw-parser-output .reflist{margin-bottom:0.5em;list-style-type:decimal}@media screen{.mw-parser-output .reflist{font-size:90%}}.mw-parser-output .reflist .references{font-size:100%;margin-bottom:0;list-style-type:inherit}.mw-parser-output .reflist-columns-2{column-width:30em}.mw-parser-output .reflist-columns-3{column-width:25em}.mw-parser-output .reflist-columns{margin-top:0.3em}.mw-parser-output .reflist-columns ol{margin-top:0}.mw-parser-output .reflist-columns li{page-break-inside:avoid;break-inside:avoid-column}.mw-parser-output .reflist-upper-alpha{list-style-type:upper-alpha}.mw-parser-output .reflist-upper-roman{list-style-type:upper-roman}.mw-parser-output .reflist-lower-alpha{list-style-type:lower-alpha}.mw-parser-output .reflist-lower-greek{list-style-type:lower-greek}.mw-parser-output .reflist-lower-roman{list-style-type:lower-roman}


/* end https://en.wikipedia.org/ */
</style><div class="reflist reflist-columns references-column-width reflist-columns-2">
<ol class="references">
<li id="cite_note-WadlerPost-1"><span class="mw-cite-backlink"><b><a href="#cite_ref-WadlerPost_1-0">^</a></b></span> <span class="reference-text"><style data-mw-deduplicate="TemplateStyles:r1238218222">
/* start https://en.wikipedia.org/ */


.mw-parser-output cite.citation{font-style:inherit;word-wrap:break-word}.mw-parser-output .citation q{quotes:"\"""\"""'""'"}.mw-parser-output .citation:target{background-color:rgba(0,127,255,0.133)}.mw-parser-output .id-lock-free.id-lock-free a{background:url("./mw/Lock-green.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-limited.id-lock-limited a,.mw-parser-output .id-lock-registration.id-lock-registration a{background:url("./mw/Lock-gray-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .id-lock-subscription.id-lock-subscription a{background:url("./mw/Lock-red-alt-2.svg")right 0.1em center/9px no-repeat}.mw-parser-output .cs1-ws-icon a{background:url("./mw/Wikisource-logo.svg")right 0.1em center/12px no-repeat}body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-free a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-limited a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-registration a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .id-lock-subscription a,body:not(.skin-timeless):not(.skin-minerva) .mw-parser-output .cs1-ws-icon a{background-size:contain;padding:0 1em 0 0}.mw-parser-output .cs1-code{color:inherit;background:inherit;border:none;padding:inherit}.mw-parser-output .cs1-hidden-error{display:none;color:var(--color-error,#d33)}.mw-parser-output .cs1-visible-error{color:var(--color-error,#d33)}.mw-parser-output .cs1-maint{display:none;color:#085;margin-left:0.3em}.mw-parser-output .cs1-kern-left{padding-left:0.2em}.mw-parser-output .cs1-kern-right{padding-right:0.2em}.mw-parser-output .citation .mw-selflink{font-weight:inherit}@media screen{.mw-parser-output .cs1-format{font-size:95%}html.skin-theme-clientpref-night .mw-parser-output .cs1-maint{color:#18911f}}@media screen and (prefers-color-scheme:dark){html.skin-theme-clientpref-os .mw-parser-output .cs1-maint{color:#18911f}}


/* end https://en.wikipedia.org/ */
</style><cite class="citation web cs1"><a rel="nofollow" class="external text" href="http://homepages.inf.ed.ac.uk/wadler/papers/expression/expression.txt">"The Expression Problem"</a>.</cite></span>
</li>
<li id="cite_note-Reynolds-2"><span class="mw-cite-backlink"><b><a href="#cite_ref-Reynolds_2-0">^</a></b></span> <span class="reference-text">
<cite id="CITEREFReynolds1975" class="citation book cs1">Reynolds, John C. (1975). "User-defined Types and Procedural Data Structures as complementary approaches to Data Abstraction.". <a rel="nofollow" class="external text" href="https://www.cs.tufts.edu/~nr/cs257/archive/john-reynolds/procedural-data-structures.pdf"><i>New Directions in Algorithmic Languages</i></a> <span class="cs1-format">(PDF)</span>. IFIP Working Group 2.1 on Algol. pp.&nbsp;<span class="nowrap">157–</span>168.</cite></span>
</li>
<li id="cite_note-CookOOPvsADT-3"><span class="mw-cite-backlink"><b><a href="#cite_ref-CookOOPvsADT_3-0">^</a></b></span> <span class="reference-text">
<cite id="CITEREFCook1990" class="citation book cs1"><a href="William_Cook_(computer_scientist)" title="William Cook (computer scientist)">Cook, William</a> (1990). <a rel="nofollow" class="external text" href="https://link.springer.com/chapter/10.1007/BFb0019443">"Object-Oriented Programming versus Abstract Data Types"</a>. In Bakker, J.W. de; Roever, W.P. de; Rozenberg, G. (eds.). <i>Foundations of Object-Oriented Languages (FOOL), REX School/Workshop</i>. Lecture Notes in Computer Science. Vol.&nbsp;489. Noordwijkerhout, The Netherlands: Springer Berlin Heidelberg. pp.&nbsp;<span class="nowrap">151–</span>178. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1007%2FBFb0019443">10.1007/BFb0019443</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-3-540-46450-1</bdi>.</cite></span>
</li>
<li id="cite_note-Synth-4"><span class="mw-cite-backlink"><b><a href="#cite_ref-Synth_4-0">^</a></b></span> <span class="reference-text">
<cite class="citation web cs1"><a rel="nofollow" class="external text" href="https://cs.brown.edu/~sk/Publications/Papers/Published/kff-synth-fp-oo/">"Synthesizing Object-Oriented and Functional Design to Promote Re-Use"</a>.</cite></span>
</li>
<li id="cite_note-FF-5"><span class="mw-cite-backlink"><b><a href="#cite_ref-FF_5-0">^</a></b></span> <span class="reference-text">
<cite id="CITEREFFindlerFlatt1999" class="citation journal cs1">Findler, Robert Bruce; Flatt, Matthew (1999). <a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F291251.289432">"Modular object-oriented programming with units and mixins"</a>. <i>ACM SIGPLAN Notices</i>. <b>34</b>: <span class="nowrap">94–</span>104. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F291251.289432">10.1145/291251.289432</a></span>.</cite></span>
</li>
<li id="cite_note-Mixins-6"><span class="mw-cite-backlink"><b><a href="#cite_ref-Mixins_6-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFCook1989" class="citation thesis cs1">Cook, William (1989). <a rel="nofollow" class="external text" href="https://www.cs.utexas.edu/~wcook/papers/thesis/cook89.pdf"><i>A Denotational Semantics of Inheritance</i></a> <span class="cs1-format">(PDF)</span> (PhD). Brown University.</cite></span>
</li>
<li id="cite_note-FKF-7"><span class="mw-cite-backlink"><b><a href="#cite_ref-FKF_7-0">^</a></b></span> <span class="reference-text">
<cite id="CITEREFFlattKrishnamurthiFelleisen1998" class="citation book cs1">Flatt, Matthew; Krishnamurthi, Shriram; Felleisen, Matthias (1998). "Classes and Mixins". <i>Proceedings of the 25th ACM SIGPLAN-SIGACT symposium on Principles of programming languages - POPL '98</i>. pp.&nbsp;<span class="nowrap">171–</span>183. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F268946.268961">10.1145/268946.268961</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-0897919791</bdi>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&nbsp;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:5815257">5815257</a>.</cite></span>
</li>
<li id="cite_note-K-8"><span class="mw-cite-backlink"><b><a href="#cite_ref-K_8-0">^</a></b></span> <span class="reference-text">
<cite id="CITEREFKühne1999" class="citation book cs1">Kühne, Thomas (1999). <i>A Functional Pattern System for Object-Oriented Design</i>. Darmstadt: Verlag Dr. Kovac. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-3-86064-770-7</bdi>.</cite></span>
</li>
<li id="cite_note-SB-9"><span class="mw-cite-backlink"><b><a href="#cite_ref-SB_9-0">^</a></b></span> <span class="reference-text">
<cite id="CITEREFSmaragdakisDon_Batory1998" class="citation book cs1">Smaragdakis, Yannis; Don Batory (1998). <i>Implementing Reusable Object-Oriented Components</i>. Lecture Notes in Computer Science. Vol.&nbsp;1445.</cite></span>
</li>
<li id="cite_note-Scala0-10"><span class="mw-cite-backlink"><b><a href="#cite_ref-Scala0_10-0">^</a></b></span> <span class="reference-text">
<cite id="CITEREFZengerOdersky2001" class="citation book cs1">Zenger, Matthias; Odersky, Martin (2001). "Extensible Algebraic Datatypes with Defaults". <i>Proceedings of the sixth ACM SIGPLAN international conference on Functional programming</i>. pp.&nbsp;<span class="nowrap">241–</span>252. <a href="CiteSeerX_(identifier)" class="mw-redirect" title="CiteSeerX (identifier)">CiteSeerX</a>&nbsp;<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.28.6778">10.1.1.28.6778</a></span>. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F507635.507665">10.1145/507635.507665</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>1-58113-415-0</bdi>.</cite></span>
</li>
<li id="cite_note-Scala-11"><span class="mw-cite-backlink"><b><a href="#cite_ref-Scala_11-0">^</a></b></span> <span class="reference-text">
<cite id="CITEREFZengerOdersky2005" class="citation book cs1">Zenger, Matthias; Odersky, Martin (2005). <a rel="nofollow" class="external text" href="https://homepages.inf.ed.ac.uk/wadler/fool/program/final/10/10_Paper.pdf">"Independently extensible solutions to the expression problem"</a> <span class="cs1-format">(PDF)</span>. <i>FOOL 2005</i>. ACM. <a href="CiteSeerX_(identifier)" class="mw-redirect" title="CiteSeerX (identifier)">CiteSeerX</a>&nbsp;<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.107.4449">10.1.1.107.4449</a></span>.</cite></span>
</li>
<li id="cite_note-Chambers_&amp;_Leavens,_Multi-Methods-12"><span class="mw-cite-backlink"><b><a href="#cite_ref-Chambers_&amp;_Leavens,_Multi-Methods_12-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFChambersLeavens1995" class="citation journal cs1">Chambers, Craig; Leavens, Gary T. (November 1995). <a rel="nofollow" class="external text" href="http://lib.dr.iastate.edu/cgi/viewcontent.cgi?article=1036&amp;context=cs_techreports">"Type Checking and Modules for Multi-Methods"</a>. <i>ACM Transactions on Programming Languages and Systems</i>. <b>17</b> (6): <span class="nowrap">805–</span>843. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F218570.218571">10.1145/218570.218571</a></span>.</cite></span>
</li>
<li id="cite_note-Clifton_et._al.,_MultiJava_Open_Classes-13"><span class="mw-cite-backlink"><b><a href="#cite_ref-Clifton_et._al.,_MultiJava_Open_Classes_13-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFCliftonLeavensChambersMillstein2000" class="citation book cs1">Clifton, Curtis; Leavens, Gary T.; Chambers, Craig; Millstein, Todd (2000). "MultiJava: Modular open classes and symmetric multiple dispatch for Java". <a rel="nofollow" class="external text" href="http://people.csail.mit.edu/dnj/teaching/6898/papers/multijava.pdf"><i>Proceedings of the 15th ACM SIGPLAN conference on Object-oriented programming, systems, languages, and applications</i></a> <span class="cs1-format">(PDF)</span>. pp.&nbsp;<span class="nowrap">130–</span>145. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F353171.353181">10.1145/353171.353181</a>. <a href="ISBN_(identifier)" class="mw-redirect" title="ISBN (identifier)">ISBN</a>&nbsp;<bdi>978-1-58113-200-7</bdi>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&nbsp;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:7879645">7879645</a>.</cite></span>
</li>
<li id="cite_note-14"><span class="mw-cite-backlink"><b><a href="#cite_ref-14">^</a></b></span> <span class="reference-text"><cite id="CITEREFWouter_Swierstra2008" class="citation journal cs1">Wouter Swierstra (2008). <a rel="nofollow" class="external text" href="https://doi.org/10.1017%2FS0956796808006758">"Data Types à La Carte"</a>. <i><a href="Journal_of_Functional_Programming" title="Journal of Functional Programming">Journal of Functional Programming</a></i>. <b>18</b> (4). Cambridge University Press: <span class="nowrap">423–</span>436. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1017%2FS0956796808006758">10.1017/S0956796808006758</a></span>. <a href="ISSN_(identifier)" class="mw-redirect" title="ISSN (identifier)">ISSN</a>&nbsp;<a rel="nofollow" class="external text" href="https://search.worldcat.org/issn/0956-7968">0956-7968</a>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&nbsp;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:21038598">21038598</a>.</cite></span>
</li>
<li id="cite_note-Wehr_&amp;_Thiemann,_JavaGI_Type_Classes-15"><span class="mw-cite-backlink"><b><a href="#cite_ref-Wehr_&amp;_Thiemann,_JavaGI_Type_Classes_15-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFWehrThiemann2011" class="citation journal cs1">Wehr, Stefan; Thiemann, Peter (July 2011). <a rel="nofollow" class="external text" href="http://www.stefanwehr.de/publications/WehrThiemann2011TOPLAS.html">"JavaGI: The Interaction of Type Classes with Interfaces and Inheritance"</a>. <i>ACM Transactions on Programming Languages and Systems</i>. <b>33</b> (4): <span class="nowrap">1–</span>83. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://doi.org/10.1145%2F1985342.1985343">10.1145/1985342.1985343</a></span>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&nbsp;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:13174506">13174506</a>.</cite></span>
</li>
<li id="cite_note-Carette_et_al.,_Finally_tagless,_partially_evaluated:_Tagless_staged_interpreters_for_simpler_typed_languages-16"><span class="mw-cite-backlink"><b><a href="#cite_ref-Carette_et_al.,_Finally_tagless,_partially_evaluated:_Tagless_staged_interpreters_for_simpler_typed_languages_16-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFCaretteKiselyovChung-chieh2009" class="citation journal cs1">Carette, Jacques; Kiselyov, Oleg; Chung-chieh, Shan (2009). <a rel="nofollow" class="external text" href="http://okmij.org/ftp/tagless-final/JFP.pdf">"Finally Tagless, Partially Evaluated: Tagless Staged Interpreters for Simpler Typed Languages"</a> <span class="cs1-format">(PDF)</span>. <i>J. Funct. Program</i>. <b>19</b> (5): <span class="nowrap">509–</span>543. <a href="Doi_(identifier)" class="mw-redirect" title="Doi (identifier)">doi</a>:<a rel="nofollow" class="external text" href="https://doi.org/10.1017%2FS0956796809007205">10.1017/S0956796809007205</a>. <a href="S2CID_(identifier)" class="mw-redirect" title="S2CID (identifier)">S2CID</a>&nbsp;<a rel="nofollow" class="external text" href="https://api.semanticscholar.org/CorpusID:6054319">6054319</a>.</cite></span>
</li>
<li id="cite_note-Oliveira_&amp;_Cook,_Object_Algebras-17"><span class="mw-cite-backlink">^ <a href="#cite_ref-Oliveira_&amp;_Cook,_Object_Algebras_17-0"><sup><i><b>a</b></i></sup></a> <a href="#cite_ref-Oliveira_&amp;_Cook,_Object_Algebras_17-1"><sup><i><b>b</b></i></sup></a></span> <span class="reference-text"><cite id="CITEREFOliveiraCook2012" class="citation journal cs1">Oliveira, Bruno C. d. S.; Cook, William R. (2012). <a rel="nofollow" class="external text" href="http://www.cs.utexas.edu/~wcook/Drafts/2012/ecoop2012.pdf">"Extensibility for the Masses: Practical Extensibility with Object Algebras"</a> <span class="cs1-format">(PDF)</span>. <i>Ecoop '12</i>.</cite></span>
</li>
<li id="cite_note-Code_Reuse_Through_Polymorphic_Variants-18"><span class="mw-cite-backlink"><b><a href="#cite_ref-Code_Reuse_Through_Polymorphic_Variants_18-0">^</a></b></span> <span class="reference-text"><cite id="CITEREFGarrigue2000" class="citation book cs1">Garrigue, Jacques (2000). <a rel="nofollow" class="external text" href="https://www.math.nagoya-u.ac.jp/~garrigue/papers/variant-reuse.pdf">"Code Reuse Through Polymorphic Variants"</a> <span class="cs1-format">(PDF)</span>. <i>Workshop on Foundations of Software Engineering. Sasaguri, Japan, November 2000</i>. <a href="CiteSeerX_(identifier)" class="mw-redirect" title="CiteSeerX (identifier)">CiteSeerX</a>&nbsp;<span class="id-lock-free" title="Freely accessible"><a rel="nofollow" class="external text" href="https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.128.7169">10.1.1.128.7169</a></span>.</cite></span>
</li>
</ol></div>
<div class="mw-heading mw-heading2"><h2 id="External_links">External links</h2></div>
<ul><li><a rel="nofollow" class="external text" href="http://homepages.inf.ed.ac.uk/wadler/papers/expression/expression.txt">The Expression Problem</a> by <a href="Philip_Wadler" title="Philip Wadler">Philip Wadler</a>.</li>
<li><a rel="nofollow" class="external text" href="http://www.uni-koblenz.de/~laemmel/paradigms1011/resources/xproblem.html">Lecture: The Expression Problem</a> by Ralf Lämmell.</li>
<li><a rel="nofollow" class="external text" href="http://channel9.msdn.com/Shows/Going+Deep/C9-Lectures-Dr-Ralf-Laemmel-Advanced-Functional-Programming-The-Expression-Problem">C9 Lectures: Dr. Ralf Lämmel - Advanced Functional Programming - The Expression Problem</a> at <a href="Channel_9_(discussion_forum)" class="mw-redirect" title="Channel 9 (discussion forum)">Channel 9</a>.</li>
<li><a rel="nofollow" class="external text" href="http://lampwww.epfl.ch/~odersky/papers/ExpressionProblem.html">Independently Extensible Solutions to the Expression Problem, Matthias Zenger and Martin Odersky, EPFL Lausanne</a>.</li></ul></div><!--htdig_noindex--><div><div class="zim-footer">
This article is issued from <a class="external text" title="Last edited on 2025-07-27" href="https://en.wikipedia.org/wiki/?title=Expression_problem&amp;oldid=1302818812">Wikipedia</a>. The text is available under <a class="external text" href="https://creativecommons.org/licenses/by-sa/4.0/deed.en">Creative Commons Attribution-Share Alike 4.0</a> unless otherwise noted. Additional terms may apply for the media files.
</div>
</div><!--/htdig_noindex--></div>
</div>
</main>
</div>
</div>
</div>

</body></html>